package com.yyh.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyh.entity.Follow;
import com.yyh.entity.FollowParam;
import com.yyh.entity.StudentParam;
import com.yyh.entity.Users;
import com.yyh.entity.UsersParam;
import com.yyh.service.IFollowService;
import com.yyh.util.Result;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yangyueheng
 * @since 2020-06-07
 */
@RestController
@RequestMapping("/follow")
public class FollowController {
	
	@Autowired
	IFollowService iFollowService;
	
	/**
	 * 多条件分页查询
	 * @return
	 */
	@RequestMapping("/getList")
	public Object getList(FollowParam f) {
		//分页-需要分页的配置文件
		Page<Follow> page = new Page<>(f.getPage(),f.getLimit());
		
		//多条件
		QueryWrapper<Follow> queryWrapper = new QueryWrapper<Follow>();
		if(!StringUtils.isEmpty(f.getStudentId())) {
			queryWrapper.like("student_id", f.getStudentId());
		}
		if(!StringUtils.isEmpty(f.getStartTime())) {
			queryWrapper.gt("follow_time", f.getStartTime());
		}
		if(!StringUtils.isEmpty(f.getEndTime())) {
			queryWrapper.lt("follow_time", f.getEndTime());
		}
		IPage<Follow> ipage = iFollowService.page(page, queryWrapper);
		List<Follow> data = ipage.getRecords();
		long total = ipage.getTotal();
		return new Result(0,"",data,total);
	}
	
	/**
	 * 获取跟踪列表
	 * @param users
	 * @return
	 */
	@RequestMapping("/getFollow")
    public Object getFollow(FollowParam f){
        List<FollowParam> zxs = iFollowService.getFollow(f);
        return new Result(0,"跟踪列表",zxs,(long) zxs.size());
	}

}
